<{if $type != ""}>
<script type="text/javascript"><!--
var selected;

function selectRowEffect(object, buttonSelect) {
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }

  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;

// one button is not an array
  if (document.checkout_address.address[0]) {
    document.checkout_address.address[buttonSelect].checked=true;
  } else {
    document.checkout_address.address.checked=true;
  }
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

//--></script>

<{/if}>

<script type="text/javascript"><!--
var form = "";
var submitted = false;
var error = false;
var error_message = "";

function check_input(field_name, field_size, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_radio(field_name, message) {
  var isChecked = false;

  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var radio = form.elements[field_name];

    for (var i=0; i<radio.length; i++) {
      if (radio[i].checked == true) {
        isChecked = true;
        break;
      }
    }

    if (isChecked == false) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_select(field_name, field_default, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == field_default) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_form() {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = document.address_book;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_radio("gender", "Please select your Gender.");

  check_input("firstName", 2, "Your First Name must contain a minimum of 2 characters.");
  check_input("lastName", 2, "Your Last Name must contain a minimum of 2 characters.");

  check_input("dob", 10, "Your Date of Birth must be in this format: MM/DD/YYYY (eg 05/21/1970)");

  check_input("email", 6, "Your E-Mail Address must contain a minimum of 6 characters.");
  check_input("street", 5, "Your Street Address must contain a minimum of 5 characters.");
  check_input("zipCode", 4, "Your Post Code must contain a minimum of 4 characters.");
  check_input("city", 3, "Your City must contain a minimum of 3 characters.");

  check_input("state", 2, "Your State must contain a minimum of 2 characters.");

  check_select("country", "", "You must select a country from the Countries pull down menu.");

  check_input("telephone", 3, "Your Telephone Number must contain a minimum of 3 characters.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;	
	form.actionForm.value = "submit";
	form.submit();
    return true;
  }
}

function check_form_change() {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = document.address_book;
 
submitted = true;	
form.actionForm.value = "change";
form.submit();
return true;
  
}
//--></script>

<h1><{$title}></h1>
<form name="address_book" action="<{$APPLICATION_URL}>/<{$ownerName}>MyAccount/addAddress" method="post">

  <div class="contentText">
    <div style="float: right;">
      <strong>Please Select</strong>    </div>

    Please select the preferred shipping address if the items in this order are to be delivered elsewhere.  </div>

  <div class="contentText">
    <table border="0" width="100%" cellspacing="0" cellpadding="2">

      <tbody>
	  <{assign var=i value=0}>
  
   <{foreach item=addressEntity from=$listAddress}>
	 

      <tr class="moduleRowOver" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="selectRowEffect(this, <{$i}>)">

        <td><strong><{$addressEntity->getName()}></strong></td>
        <td align="right"><input type="radio" name="address" value="<{$addressEntity->id}>"></td>
      </tr>
      <tr>
        <td colspan="2" style="padding-left: 15px;"><{$addressEntity->street}>, <{$addressEntity->city}> ,<{$addressEntity->getState()}>, <{$addressEntity->postcode}>, <{$addressEntity->getCountry()}></td>
      </tr>
	    <{assign var=i value=$i+1}>
<{/foreach}>

    </tbody></table>
  </div>
  
  <div class="buttonSet">
    <span class="buttonAction"><input type="hidden" name="action" value="process"><span class=""><div id="tdb1" type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary ui-priority-primary" role="button" aria-disabled="false" onclick="return check_form_change();"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-e"></span>Change Address</div></span><script type="text/javascript">$("#tdb1").button({icons:{primary:"ui-icon-triangle-1-e"}}).addClass("ui-priority-primary").parent().removeClass("tdbLink");</script></span>
  
  <br />
  <br />


<div class="contentContainer">
  <div>
    <span class="inputRequirement" style="float: right;">* Required information</span>
    <h2>New Address Book Entry</h2>
  </div>

  <div class="contentText">
    <table border="0" width="100%" cellspacing="2" cellpadding="2">


      <tbody>
	  <{if $errorMessage != ""}>
	  <div class="inputRequirement"><{$errorMessage}></div>
	  <{/if}>
	  <tr>
        <td class="fieldKey">Gender:</td>
        <td class="fieldValue"><input type="radio" name="gender" value="m">&nbsp;&nbsp;Male&nbsp;&nbsp;<input type="radio" name="gender" value="f">&nbsp;&nbsp;Female&nbsp;<span class="inputRequirement">*</span></td>
      </tr>


      <tr>
        <td class="fieldKey">First Name:</td>
        <td class="fieldValue"><input type="text" name="firstName">&nbsp;<span class="inputRequirement">*</span></td>
      </tr>
      <tr>
        <td class="fieldKey">Last Name:</td>
        <td class="fieldValue"><input type="text" name="lastName">&nbsp;<span class="inputRequirement">*</span></td>
      </tr>


      <tr>
        <td class="fieldKey">Company Name:</td>
        <td class="fieldValue"><input type="text" name="company">&nbsp;</td>
      </tr>
      <tr>
        <td class="fieldKey">Street Address:</td>
        <td class="fieldValue"><input type="text" name="street">&nbsp;<span class="inputRequirement">*</span></td>
      </tr>
      <tr>
        <td class="fieldKey">Post Code:</td>
        <td class="fieldValue"><input type="text" name="zipCode">&nbsp;<span class="inputRequirement">*</span></td>
      </tr>
      <tr>
        <td class="fieldKey">City:</td>
        <td class="fieldValue"><input type="text" name="city">&nbsp;<span class="inputRequirement">*</span></td>
      </tr>
       <tr>
					<td class="fieldKey">Country:</td>
					<td class="fieldValue"><select name="country" onchange="javascript:document.location.href='<{$APPLICATION_URL}>/<{$ownerName}>MyAccount/addAddress/countryId/' + this.value;"><option value=""
								selected="selected">Please Select</option> 
							<{foreach item=country from=$listCountry}>
								<option value="<{$country->id}>" <{if $country->id == $countryId}>selected="selected"
								<{/if}>><{$country->name}></option>
							<{/foreach}>
					</select>&nbsp;<span class="inputRequirement">*</span>
					</td>
				</tr>
				<tr>
					<td class="fieldKey">State/Province:</td>
					<td class="fieldValue">
						<select name="state">
						<option value=""
								selected="selected">Please Select</option> 
							<{foreach item=state from=$listState}>
								<option value="<{$state->id}>" <{if $state->id == $stateId}>selected="selected"
								<{/if}>
								><{$state->name}></option>
							<{/foreach}>
					</select>&nbsp;<span class="inputRequirement">*</span>
				</tr>
      <tr>
        <td class="fieldValue" colspan="2"><input type="checkbox" name="primary" value="on" id="primary"> Set as primary address.</td>
      </tr>
    </tbody></table>
  </div>
  <div class="buttonSet">
    <span class="buttonAction"><input type="hidden" name="action" value="process"><span class=""><div id="tdb5" type="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary ui-priority-primary" role="button" aria-disabled="false" onclick="return check_form();"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-e"></span>Add Address</div></span><script type="text/javascript">$("#tdb5").button({icons:{primary:"ui-icon-triangle-1-e"}}).addClass("ui-priority-primary").parent().removeClass("tdbLink");</script></span>
    <span class=""><a id="tdb6" href="<{$APPLICATION_URL}>/<{$ownerName}>MyAccount" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary ui-priority-secondary" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-w"></span>Back</a></span><script type="text/javascript">$("#tdb6").button({icons:{primary:"ui-icon-triangle-1-w"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");</script>  </div>
</div>
<input type="hidden" id="actionForm" name="actionForm" value=""/>
<input type="hidden" id="type" name="type" value="<{$type}>"/>
<input type="hidden" id="confirm" name="confirm" value="<{$confirm}>"/>
</form>